<template>
  <div class="hot-goods">
    <navbar/>
    <div class="ht-banner">
      <img src="http://p4.music.126.net/gpsv3iVz1eGOnUT-pX775g==/19078725765440639.jpg" alt="">
    </div>
    <div class="re-body">
      <div class="re-item" v-for="(item,index) in list" :key="item.id">
        <div class="re-body-img" @mouseenter="enter(index)" @mouseleave="leave()">
          <img :src="item.imgUrl" :title="item.name" :alt="item.name" :class="showMask && currentIndex === index ? 'scale-img' : '' ">
        </div>
        <!--鼠标经过图片时显示遮罩-->
        <div class="mask"
             v-if="showMask && currentIndex === index"
             @mouseenter="enter(index)"
             @mouseleave="leave()"
             @click="handleClick(item.id)"
             :title="item.name">
          <i class="el-icon-search"></i>
        </div>
        <!--遮罩结束-->
        <div class="img-desc">
          <span class="bargain border" v-if="item.bargains">特价</span>
          <span class="bargain border" v-if="item.isHot">热门</span>
          <span class="goods-name">{{ item.name}}</span>
          <p>
            <span>¥</span> <span>{{ item.price | money }}</span>
          </p>
        </div>
      </div>
    </div>
    <hot-footer/>
  </div>
</template>


<script>
  import Navbar from '@/public/components/HeaderNavbar'
  import Footer from '@/public/components/Footer'
  import axios from 'axios'
  export default {
    name: "HotProduct",
    data () {
      return {
        list: [],
        showMask: false,
        currentIndex: ''
      }
    },
    methods: {
      getHotInfo () {
        axios.get('/api/index.json')
          .then(this.getHotInfoSucc)
          .catch(err=> {
            console.log(error)
          })
      },
      getHotInfoSucc (res) {
        console.log(res)
        if (res && res.status === 200) {
          this.list = res.data.data.recommend
        }
      },
      handleClick (id) {
        this.$router.push({path:'/goods_info', query: { itemId: id }, meta: { title: '商品详情'}})
      },
      enter (index) {
        this.currentIndex = index;
        this.showMask = true;
      },
      leave () {
        this.showMask = false;
        this.currentIndex = ''
      }
    },
    mounted () {
      this.getHotInfo()
    },
    components: {
      Navbar,
      HotFooter: Footer
    }
  }
</script>

<style lang="stylus" scoped>
  @import '~@/assets/css/common.styl'
  .ht-banner {
    padding $bannerPadding
    margin-top $bannerMarginTop
  }
  .ht-banner img {
    width: 100%
  }
  .re-body {
    position: relative;
    padding: $commonPadding;
  }
  .re-item {
    display: inline-block;
    width: 24%;
    margin: 0 5px;
    text-align: center;
    position: relative;
  }
  .re-body-img {
    overflow hidden
  }
  .re-body-img img {
    width: 100%;
    background: #fbfbfb;
    cursor: pointer;
    transition: all 0.6s;
  }
  .scale-img {
    transform: scale(1.2);
  }
  .mask {
    background: rgba(76, 76, 76, 0.44);
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 62px;
    line-height: 263px;
    font-size: 30px;
    color: #ffc904;
    cursor: pointer
  }
  .img-desc {
    margin-top: 10px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    width: 260px;
    line-height: 24px;
  }
  .img-desc span.bargain {
    font-size: 12px;
    font-weight: 400;
    font-family: sans-serif;
    color: #f00;
    padding: 0px 5px;
  }
  .img-desc span.border:before {
    border-color: #f00;
    border-radius: 5px;
  }
  .img-desc span.goods-name {
    font-size: 14px;
  }
  .img-desc p {
    margin: 0;
    font-size: 12px
  }
  .img-desc p span:last-child {
    color: #f00;
    font-size: 14px;
  }

</style>
